package com.truyen.service;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContext;

import com.truyen.persistence.entity.Account;
import com.truyen.utils.PagingInfo;

public interface UserService {
	
	//tim lst account theo dt
	List<Account> findByMobile(String mobile);

	//tim lst theo level
	List<Account> findByLevel(int level);

	//tim lst theo isActive
	List<Account> findByIsActive(boolean isActive);

	//tim lst theo gia tri
	List<Account> findByProperty(String property, Object value);

	/*
	 * Get current logging in user
	 */
	Account getCurrentLoggedInUser();

	/*
	 * Get current context of spring security
	 */
	SecurityContext getSecurityContext();

	/**
	 * Authenticate user with the request instance to interact with Session
	 * 
	 * @param userName
	 * @param password
	 * @param request
	 * @return true/false
	 */
	boolean authenticate(String userName, String password,
			HttpServletRequest request);

	/**
	 * authenticate user with simple user/pwd pair
	 * 
	 * @param userName
	 * @param pwd
	 * @return true/false
	 */
	boolean authenticate(String userName, String pwd);

	void save(Account u);

	/**
	 * Update an existing user
	 * 
	 * @param user with changed information
	 */
	void update(Account u);

	@PreAuthorize("hasRole('ROLE_ADMIN')")
	void delete(Account u);

	/**
	 * @param userName
	 * @param isActive
	 */
	void deleteUser(String email, boolean isActive);

	/**
	 * Check whether email exist in db
	 * 
	 * @param email
	 * @return
	 */
	boolean checkExists(String email);

	//cap nhat mat khau
	boolean savePwd(String email, String pwd);

	//lay tat ca user co phan trang
	List<Account> getAllUsers(PagingInfo pInfo);

	//tim user theo kw
	List<Account> getUsers(String kw, PagingInfo pInfo);

	//tim account theo email hoac nick name
	Account findItemByProperty(String column, Object value);

	//update account theo cot long
	void updateColumLong(long id, String column, int i);

	//tim account theo id
	Account findById(Long idAccount);

	//update account theo cot string
	void updateColumnString(long id, String column, String value);

	//lay tat ca danh sach user
	List<Account> getAllLst(String kwSearch, String sort, String sortBy,
			PagingInfo pInfo);

	//cap nhat tai khoan theo cot boolan
	void updateBoolean(Long id, String column);

	//chinh sua tai khoan
	boolean updateAccount(Long id, int level, String fullName, String avatar,
			String address, String mobile, boolean sex, Date birthDay,
			long liked, long toCoin);

	//cap nhat thong tin thanh vien
	boolean updateAccountInfo(Long id, String fullName, String address,
			String mobile, boolean sex, Date birthD);

	//cap nhat user thay doi mat khau
	boolean updatePwdAccount(Long id, String pwd);

}
